package com.guigu.buy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.guigu.buy.pojo.Supplier;
import com.guigu.buy.mapper.SupplierMapper;
import com.guigu.buy.service.ISupplierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.buy.utils.PageUtils;
import com.guigu.buy.vo.SupplierVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author com.guigu
 * @since 2024-05-15
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {

    @Autowired
    SupplierMapper supplierMapper;
    @Override
    public int insertSupplier(Supplier supplier) {
        return supplierMapper.insertSupplier(supplier);
    }

    @Override
    public PageUtils<Supplier> AllList(int pageNo, int pageSize, SupplierVo vo) {
        QueryWrapper<Supplier> wrapper = new QueryWrapper<>();
        if(vo!=null){
            if(vo.getSupplierName()!=null){
                wrapper.eq("supplier_name",vo.getSupplierName());
            }
        }
        wrapper.eq("supplier_status",0);
        List<Supplier> list = this.list(wrapper);
        PageInfo<Supplier> pageInfo = new PageInfo<>(list);
        PageUtils<Supplier> pageUtils = new PageUtils<>();
        pageUtils.setTotal(pageInfo.getTotal());
        pageUtils.setRows(pageInfo.getList());
        return pageUtils;
    }

    @Override
    public PageUtils<Supplier> selAudit(int pageNo, int pageSize, SupplierVo vo) {
        QueryWrapper<Supplier> wrapper = new QueryWrapper<>();
        if(vo!=null){
            if(vo.getSupplierName()!=null){
                wrapper.eq("supplier_name",vo.getSupplierName());
            }
        }
        wrapper.eq("supplier_status",0);
        wrapper.eq("user_supplier_tag",0);
        List<Supplier> list = this.list(wrapper);
        PageInfo<Supplier> pageInfo = new PageInfo<>(list);
        PageUtils<Supplier> pageUtils = new PageUtils<>();
        pageUtils.setTotal(pageInfo.getTotal());
        pageUtils.setRows(pageInfo.getList());
        return pageUtils;
    }
}
